<!DOCTYPE html>
<html lang="en">
<head>
    <!-- 引入vue和axios -->
    <script src="js/plugins/vue/dist/vue.js"></script>
    <script src="js/plugins/axios/dist/axios.js"></script>
    <script src="js/plugins/common.js"></script>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="app"></div>
</body>

    <script type="text/javascript">
        new Vue({
            el:"#app",
            data:{},
            methods:{},
            mounted(){
                // http://bugtracker.itsource.cn/callback.html?code=0714iZ000W7VhO1UrD300Xo0ds24iZ0G&state=1
                var url = location.href; // 获取当前路径
                var obj = parseUrlParams2Obj(url); // 调用工具截取code
                // Obj = [code:0714iZ000W7VhO1UrD300Xo0ds24iZ0G, state:1]
                var code = obj.code; // code = 0714iZ000W7VhO1UrD300Xo0ds24iZ0G
                this.$http.get("/login/weChat/" + code)
                    .then(res=>{
                        if(res.data.success){ // 微信扫码登录已经绑定过
                            // 将数据 key(token)  user   使用localStorage存到浏览器
                            var token = res.data.resultObj.token; // 获取token
                            var logininfo = res.data.resultObj.logininfo; // 获取logininfo

                            localStorage.setItem("token",token); // 存数据
                            // logininfo 为一个对象   JSON.stringify(logininfo) 将对象转为字符串
                            localStorage.setItem("logininfo",JSON.stringify(logininfo));

                            // 跳转到首页
                            location.href = "index.html";
                        } else { // 微信扫码登录没有绑定，直接跳转到绑定页面
                            // 获取参数access_token 和 openid，后端拼接好的直接取
                            var param = res.data.resultObj;
                            // 将参数拼接到绑定路径上，绑定成功后直接从路径上获取数据存到数据库
                            location.href = "binder.html" + param;
                        }
                    }).catch(res=>{

                })
            },
        })
    </script>


</html>